package com.thb.pay.manage.web.payment;


import com.thb.pay.api.payment.CurrencyTypeServiceApi;
import com.thb.pay.api.payment.vo.req.CurrencyTypePageReq;
import com.thb.pay.api.payment.vo.req.CurrencyTypeReq;
import com.thb.pay.api.payment.vo.resp.CurrencyTypeVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.core.utils.R;
import com.thb.pay.manage.comm.controller.BaseController;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 货币-类型表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-10-23
 */
@Slf4j
@RestController
@RequestMapping("api/sys/currencyType")
public class CurrencyTypeController extends BaseController {

    @Autowired
    private CurrencyTypeServiceApi currencyTypeServiceApi;

    @PostMapping("/list")
    public R list(@RequestBody CurrencyTypePageReq pageReq) {
        PageResult<CurrencyTypeVo> pageResult = currencyTypeServiceApi.findPage(pageReq);
        return R.okData(pageResult);
    }

    @RequestMapping("/allList")
    public R allList() {
        List<CurrencyTypeVo> resultDataList = currencyTypeServiceApi.findAllList();
        return R.okData(resultDataList);
    }

    @RequestMapping("/get")
    public R get(@RequestParam("id") Long id) {
        CurrencyTypeVo resultData = currencyTypeServiceApi.getById(id);
        return R.okData(resultData);
    }

    @PostMapping("/add")
    public R add(@RequestBody CurrencyTypeReq currencyTypeReq) {
        currencyTypeServiceApi.add(currencyTypeReq);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestParam("currencyTypeIds") String currencyTypeIds) {
        List<Long> resIds = parseStrIdsToList(currencyTypeIds);
        if (CollUtil.isNotEmpty(resIds)) {
            currencyTypeServiceApi.deleteBatchIds(resIds);
        }
        return R.ok();
    }

    @PostMapping("/update")
    public R update(@RequestBody CurrencyTypeReq currencyTypeReq) {
        currencyTypeServiceApi.update(currencyTypeReq);
        return R.ok();
    }
}
